﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Models;
using NHibernate;
using DataAccessObject.Hibernate;
using DataAccessObject.Cache;
using Core;
using DataAccessObject;

namespace WebAPI.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            return View();
        }
        public ActionResult test()
        {
            IDao dao = IoC.Resolve<IDao>();
            IEnumerable<IDao> classList = IoC.ResolveAll<IDao>();
            //IDao dao = new BaseDao(IoC.Resolve<IHSessionFactory>("Web").GetCurrentSession());
            Product product = new Product();
            product.Name = "西瓜";
            product.Price = 12.00M;
            //dao.Save(product);
            var list = dao.FindAll<Product>();
            ViewBag.Title = "Home Page";

            return Json(new { status = 0, data = list }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult redis()
        {
            Product product1 = new Product();
            product1.Id = 1;
            product1.Name = "冬瓜";
            product1.Price = 12.00M;
            Product product2 = new Product();
            product2.Id = 2;
            product2.Name = "西瓜";
            product2.Price = 12.00M;
            Product product3 = new Product();
            product3.Id = 3;
            product3.Name = "南瓜";
            product3.Price = 12.00M;
            //IList<Product> list_in = new List<Product>() { product1, product2, product3 };

            #region Redis

            Message msg1 = new Message();
            msg1.id = Guid.NewGuid();
            msg1.type = MessageType.PUBLIC;
            msg1.body = "PUBLIC Message 01";
            Message msg2 = new Message();
            msg2.id = Guid.NewGuid();
            msg2.type = MessageType.GROUP;
            msg2.body = "GROUP Message 02";
            Message msg3 = new Message();
            msg3.id = Guid.NewGuid();
            msg3.type = MessageType.PRIVATE;
            msg3.body = "PRIVATE Message 03";
            IList<Message> list_in = new List<Message>() { msg1, msg2, msg3 };

            RedisCache.Add<Message>(list_in);

            IList<Message> list_out = RedisCache.GetAll<Message>(); 
            #endregion
            return Json(new { status = 0, data = list_out }, JsonRequestBehavior.AllowGet);
        }
        
    }
}
